package com.zcp.pcsuitall;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import java.util.LinkedList;

public class IntentReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if ("com.zcp.pcsuitall.phone.receiver.closeService".equals(intent.getAction())) {

            String name = "all";
            if (intent.getExtras() != null) {
                name = intent.getExtras().getString("name");
            }
            Log.e("IntentReceiver", "receive message==" + name);
            if (name == null) {
                name = "all";
            }
            for (ActivityInterface currentObject : catchContext) {
                currentObject.stopActivity(name);
            }
//            abortBroadcast();
        }
    }
    
    /**
     * 注册关闭服务。在关闭的时候会被移除。
     * @param context
     */
    public static void register(ActivityInterface context)
    {
        catchContext.add(context);
    }
    
    /**
     * 注册关闭服务。在关闭的时候会被移除。
     * @param context
     */
    public static void unRegister(ActivityInterface context)
    {
        catchContext.remove(context);
    }
    
    private static LinkedList<ActivityInterface> catchContext=new LinkedList<ActivityInterface>();   

}
